package com.zhiyou10.crowdfunding.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhiyou10.crowdfunding.service.IAdminService;
import com.zhiyou10.crowdfunding.vo.Admin;
import com.zhiyou10.crowdfunding.vo.mapper.AdminMapper;

@Service("adminServiceImpl")
public class AdminServiceImpl implements IAdminService {
	@Autowired
	private AdminMapper mapper;

	@Override
	public boolean add(Admin vo) throws Exception {
		// TODO Auto-generated method stub
		// System.out.println("***********");
		return this.mapper.doCreate(vo);
	}

	@Override
	public boolean edit(Admin vo) throws Exception {
		// TODO Auto-generated method stub
		return this.mapper.doUpdate(vo);
	}

	@Override
	public boolean remove(Set<Integer> ids) throws Exception {
		// TODO Auto-generated method stub
		return this.mapper.doRemoveBatch(ids);
	}

	@Override
	public Admin get(Integer id) throws Exception {
		// TODO Auto-generated method stub
		return this.mapper.findById(id);
	}

	@Override
	public List<Admin> list() throws Exception {
		// TODO Auto-generated method stub
		return this.mapper.findAll();
	}

	/*@Override
	public Map<String, Object> list(int currentPage, int lineSize) throws Exception {
		// TODO Auto-generated method stub
		return this.mapper.findAllSplit(map);
	}*/
	@Override
	public List<Admin> findAllSplit(Map<String, Object> map) throws Exception {
		// TODO Auto-generated method stub
		return this.mapper.findAllSplit(map);
	}
	@Override
	public Long findAllCount() throws Exception {
		// TODO Auto-generated method stub
		return this.mapper.findAllCount();
	}

	@Override
	public Admin login(String accountName, String password) throws Exception {
		
		Map<String, String> map = new HashMap<>();
		map.put("accountName", accountName);
		map.put("password", password);
		// TODO Auto-generated method stub
		//System.out.println("---3---");
		//System.out.println(map.get("accountName"));
		//System.out.println(mapper);
		Admin admin = this.mapper.findAdmin(map);
		//System.out.println("---4---");
		return admin;
	}

}
